package com.sun.alen.mapper;

import com.sun.alen.entity.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StudentMapper {

    @Insert("INSERT INTO student (studentId, studentName, studentPassword, studentEmail, studentPhone, studentSex, studentTime, studentNation, studentNativePlace, studentPhoto, classId, teacherId, professionId)" +
            "VALUES (#{studentId}, #{studentName}, #{studentPassword}, #{studentEmail}, #{studentPhone}, #{studentSex}, #{studentTime}, #{studentNation}, #{studentNativePlace}, #{studentPhoto}, #{classId}, #{teacherId}, #{professionId})")
    boolean add(Student student);
    @Update("UPDATE student SET " +
            "    studentName = #{studentName}, " +
            "    studentPassword = #{studentPassword}, " +
            "    studentEmail = #{studentEmail}, " +
            "    studentPhone = #{studentPhone}, " +
            "    studentSex = #{studentSex}, " +
            "    studentTime = #{studentTime}, " +
            "    studentNation = #{studentNation}," +
            "    studentNativePlace = #{studentNativePlace}," +
            "    studentPhoto = #{studentPhoto}," +
            "    classId = #{classId}, " +
            "    teacherId = #{teacherId}, " +
            "    professionId = #{professionId} " +
            "WHERE " +
            "    studentId = #{studentId};")
    boolean update(Student student);

    @Delete("delete from student where studentId = #{id}")
    boolean delete(String id);

    @Select("select * from student limit #{start},#{pageSize}")
    List<Student> list(Integer start, Integer pageSize);

    @Select("select count(*) from student ")
    long count();

    @Select("SELECT * FROM student WHERE studentName LIKE #{input} LIMIT #{start}, #{pageSize}")
    List<Student> searchByName(String input, Integer start, Integer pageSize);

    @Select("SELECT COUNT(*) FROM student WHERE studentName LIKE #{input}")
    long countByName(String input);

    @Select("SELECT * FROM student WHERE studentSex LIKE #{input} LIMIT #{start}, #{pageSize}")
    List<Student> searchBySex(String input, Integer start, Integer pageSize);

    @Select("SELECT COUNT(*) FROM student WHERE studentSex LIKE #{input}")
    long countBySex(String input);

    @Select("SELECT * FROM student WHERE studentNativePlace LIKE #{input} LIMIT #{start}, #{pageSize}")
    List<Student> searchByNativePlace(String input, Integer start, Integer pageSize);

    @Select("SELECT COUNT(*) FROM student WHERE studentNativePlace LIKE #{input}")
    long countByNativePlace(String input);

    @Select("Select * from student where classId = #{classId}")
    List<Student> searchByClass(int classId);

    @Select("Select * from student where teacherId = #{teacherId}")
    List<Student> searchByTeacher(int teacherId);

    @Select("Select * from student where professionId = #{professionId}")
    List<Student> searchByProfession(int professionId);

    @Select("select * from student where studentName like #{input}")
    List<Student> searchIdByStudent(String input);

    @Select("select * from student")
    List<Student> all();

    @Select("select * from `student` where studentName=#{studentName} and studentPassword=#{studentPassword}")
    Student login(Student student);

    @Update("update `student` set studentPassword=#{pass} where studentPhone = #{phone}")
    boolean repass(String phone, String pass);



    //分页查看学生
    @Select("select * from student where teacherId = #{teacherId} limit #{start},#{pageSize}")
    List<Student> listByTeacher(Integer teacherId, Integer start, Integer pageSize);

    @Select("select COUNT(*) from student where teacherId = #{teacherId}")
    Long countByTeacher(Integer teacherId);



    @Select("select * from student where professionId =#{input} and teacherId =#{id}")
    List<Student> searchByProfessionId(Integer input,Integer id);

    @Select("select * from student where classId =#{input} and teacherId = #{id}")
    List<Student> searchByClassId(Integer input,Integer id);

    @Select("select * from student where studentName  like #{input} and teacherId = #{id} limit #{start},#{pageSize}")
    List<Student> searchByNameAndTeacher(String input,Integer id,int start,int pageSize);


    @Select("select * from student where teacherId =#{input}")
    List<Student> searchByTeacherId(Integer input);

    @Select("select * from student where teacherId =#{teacherId}")
    List<Student> studentAll(Integer teacherId);

    @Select("select count(*) from student where studentName like #{input} and teacherId = #{teacherId}")
    long countByNameAndTeacher(String input, Integer teacherId);

    @Select("select * from student where studentName like #{input} and teacherId =#{teacherId}")
    List<Student> searchByStudentName(String input,Integer teacherId);

    @Select("select * from student where classId = #{id}")
    List<Student> getStuByMain(String id);

    @Update("update `student` set studentPassword =#{studentPassword} where studentId = #{studentId}")
    boolean updatePassword(Student student);

    @Select("select * from `student` where studentId=#{studentId}")
    Student selectById(int studentId);
}
